package cn.pugle.base.collect;

/**
 * 不好好实现hashCode, 也不好好实现compare, hashmap的get也能退化成O(n)的?
 *
 * @author tzp
 * @since 2020/9/25
 */
public class MyHashMapApp {
    public static class DummyInt implements Comparable<DummyInt> {
        public int data;

        public DummyInt(int data) {
            this.data = data;
        }

        @Override
        public boolean equals(Object o) {
            if (this == o) return true;
            if (o == null || getClass() != o.getClass()) return false;

            DummyInt dummyInt = (DummyInt) o;

            return data == dummyInt.data;
        }

        @Override
        public int hashCode() {
            return 1;
        }

        @Override
        public int compareTo(DummyInt o) {
            return 0;
        }

        @Override
        public String toString() {
            return "DummyInt{" + data + '}';
        }
    }

    public static void main(String[] args) {
        MyHashMap<Object, Object> map = new MyHashMap<>();
        for (int i = 0; i < 100; i++) {
            map.put(new DummyInt(i), i);
        }
        System.out.println(map.get(new DummyInt(4)));
        System.out.println(map.get(new DummyInt(97)));
        System.out.println(map.get(new DummyInt(11)));
    }
}
